/**
 * 
 * v.10
 * stanley
 * 2025-11-04 10:11:51
 * 
 * */
layui.define(['jquery'],
    function (exports) {
        var $ = layui.jquery;
        var kaBgUrl = new function () {
            this.initUrlData = function () { //
                var kaBgUrlData = {}
                var dtStr = sessionStorage.getItem("kaBgUrlDataName")
                var dt = undefined;
                if (dtStr != undefined && dtStr != null && dtStr != "" && dtStr != "{}") {
                    if (dtStr.indexOf(".json") > 0 && top.dev) {
                        kaBgUrlData = layui.kaBgUrl.ajax();
                    } else {
                        dt = JSON.parse(dtStr);
                    }
                }
                if (dt == undefined || dt == "" || JSON.stringify(dt) == "{}") {
                    if (top.dev) {
                        kaBgUrlData = layui.kaBgUrl.ajax();
                    } else {
                        kaBgUrlData = layui.kaBgUrl.bdAjax();
                    }
                } else {
                    kaBgUrlData = dt;
                }
                return kaBgUrlData;
            }
            this.url = function (type) {
                var kaBgUrlData = kaBgUrl.initUrlData();
                if (top.dev && kaBgUrlData != undefined && kaBgUrlData[type] != undefined) {
                    // top.layui.layer.msg("未获取对应后台请求链接", { icon: 2, skin: 'ka-error-layer', time: 1200000, shade: [0.1, '#fff'] });
                    kaBgUrlData[type].url = kaCtx.location() + kaBgUrlData[type].url;
                }
                if (kaBgUrlData == undefined || kaBgUrlData[type] == undefined || kaBgUrlData[type] == null) {
                    var bdKaBgUrlData = layui.kaBgUrl.bdAjax();
                    return bdKaBgUrlData[type];
                }
                return kaBgUrlData[type];
            }
            this.ajaxUrl = function () {
                if (top.kaBgUrlJosn == undefined || top.kaBgUrlJosn.url == undefined || top.kaBgUrlJosn.url == null || top.kaBgUrlJosn.url == "") {
                    top.kaBgUrlJosn = {
                        "url": "../component/datajson/kaBgUrlData.json",
                        "async": false,
                        "methodType": "GET",
                        "contentType": "json"
                    };
                }
            }
            this.ajax = function () {  //远程 ajax
                var kaBgUrlData = {};
                $.ajax({
                    url: top.kaBgUrlJosn.url,
                    type: top.kaBgUrlJosn.methodType,
                    data: {},
                    contentType: getKaContentType(top.kaBgUrlJosn.contentType),
                    dataType: getKaDataType(top.kaBgUrlJosn.contentType),
                    async: false, //同步 false
                    loadLayer: 0,
                    beforeSend: function (xhr) { },
                    success: function (re) {
                        if(re.data != undefined){
                            kaBgUrlData = re.data;
                            sessionStorage.setItem("kaBgUrlDataName", JSON.stringify(kaBgUrlData));
                        } else {
                            kaBgUrlData = undefined;
                        }
                    },
                    error: function () { }
                });
                return kaBgUrlData
            }
            this.bdAjax = function () { // 本地 ajax
                var bdKaBgUrlData = {};
                var bdKaBgUrlJosn = {
                    "url": "../component/datajson/kaBgUrlData.json",
                    "async": false,
                    "methodType": "GET",
                    "contentType": "json"
                };
                $.ajax({
                    url: bdKaBgUrlJosn.url,
                    type: bdKaBgUrlJosn.methodType,
                    data: {},
                    contentType: getKaContentType(bdKaBgUrlJosn.contentType),
                    dataType: getKaDataType(bdKaBgUrlJosn.contentType),
                    async: false, //同步 false
                    loadLayer: 0,
                    beforeSend: function (xhr) { },
                    success: function (re) {
                        bdKaBgUrlData = re.data;
                    },
                    error: function () { }
                });
                return bdKaBgUrlData;
            }
        };
        exports('kaBgUrl', kaBgUrl);
    }
)